package com.yonyou.pmclouds.personnel.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.outter.user.UserInfoServerQuery;
import com.yonyou.pmclouds.personnel.entity.PersonnelVO;
import com.yonyou.pmclouds.user.entity.UserInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author chulf
 * @Date 2020/4/15
 * @Description
 **/
@Component
public class YhtUserRefBeforeProcess implements SingleProcessor<PersonnelVO> {

    @Autowired
    private UserInfoServerQuery userInfoServerQuery;

    @Override
    public void process(PersonnelVO vo, PersonnelVO orig) throws BusinessException {
        if (StringUtils.isEmpty(vo.getUserId())) {
            //进行友互通用户关联
            UserInfo userInfo = userInfoServerQuery.getUserIdByContact(vo.getPhone(), vo.getEmail());

            if (userInfo != null) {
                vo.setUserId(userInfo.getUserId());
                if (vo.getUserName() == null) vo.setUserName(userInfo.getUserCode());
                if (vo.getPhone() == null) vo.setPhone(userInfo.getUserMobile());
                if (vo.getEmail() == null) vo.setEmail(userInfo.getUserEmail());
            }

        }
    }
}
